package com.tdkj.service.common.impl;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.hibernate.Query;
import org.springframework.stereotype.Component;
import com.tdkj.model.risevalue.BeanAdvert;
import com.tdkj.model.risevalue.BeanAdvertAuctionInfo;
import com.tdkj.service.BaseService;
import com.tdkj.service.common.IBeanADService;
@Component("beanADService")
public class BeanADServiceImpl extends BaseService implements IBeanADService{
	private  Map<String,String> com=null;
	private  Map<String,String> clm=null;
	private  Map<String,String> mdm=null;
	private  Map<String,String> indexm=null;
	private  Map<String,String> sindexm=null;
	public Map<String, String> getCom() {
		return com;
	}
	public void setCom(Map<String, String> com) {
		this.com = com;
	}
	public Map<String, String> getClm() {
		return clm;
	}
	public void setClm(Map<String, String> clm) {
		this.clm = clm;
	}
	public Map<String, String> getMdm() {
		return mdm;
	}
	public void setMdm(Map<String, String> mdm) {
		this.mdm = mdm;
	}
	public Map<String, String> getIndexm() {
		return indexm;
	}
	public void setIndexm(Map<String, String> indexm) {
		this.indexm = indexm;
	}
	public Map<String, String> getSindexm() {
		return sindexm;
	}
	public void setSindexm(Map<String, String> sindexm) {
		this.sindexm = sindexm;
	}
	//初始化map
	private void initMap(){
		com=new HashMap<String,String>();//内容广告位
		clm=new HashMap<String,String>();//列表广告位
		mdm=new HashMap<String,String>();//栏目首页广告位
		indexm=new HashMap<String,String>();//网站首页
		sindexm=new HashMap<String,String>();//商城首页
		
		com.put("ad_1", "content/skin/a_d/zhufuwall_946_70.gif");
		com.put("ad_2", "content/skin/a_d/zhufuwall_946_70.gif");
		com.put("ad_3", "content/skin/a_d/W020081226538850475805.gif");
		com.put("ad_4", "content/skin/a_d/ev_100_50_ad.gif");
		com.put("ad_5", "content/skin/a_d/telcom_100_50.gif");
		com.put("ad_6", "content/skin/common/common.png");
		com.put("ad_7", "content/skin/common/common.png");
		com.put("ad_8", "content/skin/common/common.png");
		com.put("ad_9", "content/skin/a_d/ev_100_50_ad.gif");
		com.put("ad_10", "content/skin/a_d/telcom_100_50.gif");
		com.put("ad_11", "content/skin/common/common.png");
		com.put("ad_12", "content/skin/a_d/946x70_lovegame.gif");
		com.put("ad_13", "content/skin/a_d/zhufuwall_946_70.gif");
		com.put("ad_14", "content/skin/a_d/zhufuwall_946_70.gif");
		
		clm.put("ad_1", "content/skin/a_d/zhufuwall_946_70.gif");
		clm.put("ad_2", "content/skin/a_d/zhufuwall_946_70.gif");
		clm.put("ad_3", "content/skin/a_d/W020081226538850475805.gif");
		clm.put("ad_4", "content/skin/a_d/ev_100_50_ad.gif");
		clm.put("ad_5", "content/skin/a_d/telcom_100_50.gif");
		clm.put("ad_6", "content/skin/common/common.png");
		clm.put("ad_7", "content/skin/common/common.png");
		clm.put("ad_8", "content/skin/common/common.png");
		clm.put("ad_9", "content/skin/a_d/ev_100_50_ad.gif");
		clm.put("ad_10", "content/skin/a_d/telcom_100_50.gif");
		clm.put("ad_11", "content/skin/common/common.png");
		clm.put("ad_12", "content/skin/a_d/946x70_lovegame.gif");
		clm.put("ad_13", "content/skin/a_d/zhufuwall_946_70.gif");
		clm.put("ad_14", "content/skin/a_d/zhufuwall_946_70.gif");
		
		mdm.put("ad_1", "content/skin/a_d/zhufuwall_946_70.gif");
		mdm.put("ad_2", "content/skin/a_d/zhufuwall_946_70.gif");
		mdm.put("ad_3", "content/skin/a_d/W020081226538850475805.gif");
		mdm.put("ad_4", "content/skin/a_d/ev_100_50_ad.gif");
		mdm.put("ad_5", "content/skin/a_d/telcom_100_50.gif");
		mdm.put("ad_6", "content/skin/common/common.png");
		mdm.put("ad_7", "content/skin/common/common.png");
		mdm.put("ad_8", "content/skin/common/common.png");
		mdm.put("ad_9", "content/skin/a_d/ev_100_50_ad.gif");
		mdm.put("ad_10", "content/skin/a_d/telcom_100_50.gif");
		mdm.put("ad_11", "content/skin/common/common.png");
		mdm.put("ad_12", "content/skin/a_d/946x70_lovegame.gif");
		mdm.put("ad_13", "content/skin/a_d/zhufuwall_946_70.gif");
		mdm.put("ad_14", "content/skin/a_d/zhufuwall_946_70.gif");
		
		
		indexm.put("ad_1", "content/skin/a_d/zhufuwall_946_70.gif");
		indexm.put("ad_2", "content/skin/a_d/zhufuwall_946_70.gif");
		indexm.put("ad_3", "content/skin/a_d/W020081226538850475805.gif");
		indexm.put("ad_4", "content/skin/a_d/ev_100_50_ad.gif");
		indexm.put("ad_5", "content/skin/a_d/telcom_100_50.gif");
		indexm.put("ad_6", "content/skin/common/common.png");
		indexm.put("ad_7", "content/skin/common/common.png");
		indexm.put("ad_8", "content/skin/common/common.png");
		indexm.put("ad_9", "content/skin/a_d/ev_100_50_ad.gif");
		indexm.put("ad_10", "content/skin/a_d/telcom_100_50.gif");
		indexm.put("ad_11", "content/skin/common/common.png");
		indexm.put("ad_12", "content/skin/a_d/946x70_lovegame.gif");
		indexm.put("ad_13", "content/skin/a_d/zhufuwall_946_70.gif");
		indexm.put("ad_14", "content/skin/a_d/zhufuwall_946_70.gif");
		
		
		sindexm.put("ad_1", "content/skin/a_d/zhufuwall_946_70.gif");
		sindexm.put("ad_2", "content/skin/a_d/zhufuwall_946_70.gif");
		sindexm.put("ad_3", "content/skin/a_d/W020081226538850475805.gif");
		sindexm.put("ad_4", "content/skin/a_d/ev_100_50_ad.gif");
		sindexm.put("ad_5", "content/skin/a_d/telcom_100_50.gif");
		sindexm.put("ad_6", "content/skin/common/common.png");
		sindexm.put("ad_7", "content/skin/common/common.png");
		sindexm.put("ad_8", "content/skin/common/common.png");
		sindexm.put("ad_9", "content/skin/a_d/ev_100_50_ad.gif");
		sindexm.put("ad_10", "content/skin/a_d/telcom_100_50.gif");
		sindexm.put("ad_11", "content/skin/common/common.png");
		sindexm.put("ad_12", "content/skin/a_d/946x70_lovegame.gif");
		sindexm.put("ad_13", "content/skin/a_d/zhufuwall_946_70.gif");
		sindexm.put("ad_14", "content/skin/a_d/zhufuwall_946_70.gif");
	}
	@Override
	public Map<String, String> findAD(String code, String type) {
		initMap();
		// TODO Auto-generated method stub
		Map<String,String> m=new HashMap<String,String>();
		BeanAdvert a=new BeanAdvert();
		a.setPagecode(code);
		a.setPagetype(type);
		String hql = "select bean from " + BeanAdvert.class.getName() +" as bean"+
		" where bean.pagecode='"+code+"' and bean.pagetype='"+type+"' "+
		" order by pagename desc";
		Query query = this.getBaseDao().getSession().createQuery(hql);
		List<BeanAdvert> al=query.list();
		for(BeanAdvert abean:al){
			List<BeanAdvertAuctionInfo> ainfos=abean.getAuctioninfos();
			for(BeanAdvertAuctionInfo aubean:ainfos){
				System.out.println(aubean.getStatus());
				if(aubean.getStatus().equals("使用中")){
					m.put(aubean.getAdvert().getCode(), aubean.getFileurl());
				}
			}
			
		}
		if(m.size()>0){
			return mergeMap(m,type);
		}else{
			if(type.equals("index")){
				return this.getIndexm();
			}else if(type.equals("sindex")){
				return this.getSindexm();
			}else if(type.equals("md")){
				return this.getMdm();
			}else if(type.equals("cl")){
				return this.getClm();
			}else{
				return this.getCom();
			}
		}
	}
	private Map<String,String> mergeMap(Map<String,String> m,String type){
		Map<String,String> map=null;
		if(type.equals("index")){
			map=this.getIndexm();
		}else if(type.equals("sindex")){
			map=this.getSindexm();
		}else if(type.equals("md")){
			map=this.getMdm();
		}else if(type.equals("cl")){
			map=this.getClm();
		}else{
			map=this.getCom();
		}
		Set<String> key = m.keySet();
        for (Iterator it = key.iterator(); it.hasNext();) {
            String k = (String) it.next();
            map.put(k, m.get(k));
        }
		return map;
	}


	
	
}
